package mvc.util;

import java.lang.reflect.Field;

import javax.servlet.http.HttpServletRequest;

import mvc.form.ActionForm;

public class FullBean {
	public FullBean() {
		
	}
	
	public static ActionForm full(HttpServletRequest request) {
		ActionForm o = null;
		try {
			@SuppressWarnings("rawtypes")
			Class clazz = Class.forName(request.getParameter("sign"));// 初始化类
			o = (ActionForm) clazz.newInstance();// 实例化类
			
			Field[] f_ar = clazz.getDeclaredFields();
			for (Field f : f_ar) {
				f.setAccessible(true);// suppress 打破三项规则：Set the accessible flag for this object to the indicated boolean value. A value of true indicates that the reflected object should suppress Java language access checking when it is used. A value of false indicates that the reflected object should enforce Java language access checks. 
				f.set(o, request.getParameter(f.getName()));// set(Object obj, Object value)
				f.setAccessible(false);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return o;
	}
}
